package com.myk.game.gobangchess.rooms;

import com.myk.game.gobangchess.constants.BoardStyleData;
import com.myk.game.gobangchess.constants.WinMode;
import com.myk.game.gobangchess.utils.GridsUtils;
import com.myk.game.gobangchess.rooms.absrooms.AbsOneTwoTwoTwoStepRoom;

/**
 * 六子棋房间
 */
public class Connect6Room extends AbsOneTwoTwoTwoStepRoom {

    public Connect6Room(String roomName) {
        super(roomName, "\t\t一款经典的新棋了，棋子形成六连珠获胜。", "六子棋",BoardStyleData.getGoBangStyle(19,19), true, true);
    }

    @Override
    public String getRuleText() {
        return "黑棋先落一枚棋子，\n" +
                "随后白黑双方轮流落下两枚棋子。\n" +
                "获胜条件：形成六子一线\n" +
                "和棋条件：无棋可走";
    }

    @Override
    public String getGameInfo() {
        signList.clear();
        signList.addAll(tempPointSigns);
        return super.getGameInfo();
    }


    @Override
    protected WinState checkWin(int row, int col) {
        int winValue = 0;
        int[][] dxdy = {{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
        for (int i = 0; i < dxdy.length; i++) {
            int dx = dxdy[i][0], dy = dxdy[i][1];
            int length = getJudgeLength(row, col, dx, dy) + getJudgeLength(row, col, -dx, -dy) - 1;
            if (length >= 6) {
                winValue = (curGrids[row][col] + 1) % 2 + 1;
            }
        }

        boolean gridFull = GridsUtils.getDataCount(curGrids, 0) == 0;

        if (winValue == 1) {
            return new WinState(WinMode.BLACK_WIN,player_black.getNickNameOrTemp() + "执黑棋战胜" + player_white.getNickNameOrTemp());
        }
        else if (winValue == 2) {
            return new WinState(WinMode.WHITE_WIN,player_white.getNickNameOrTemp() + "执白棋战胜" + player_black.getNickNameOrTemp());
        }
        else if (gridFull) {
            return new WinState(WinMode.BOTH_DRAW,player_black.getNickNameOrTemp() + "-黑棋战平" + player_white.getNickNameOrTemp() + "-白棋");
        }
        else {
            return null;
        }
    }

}
